package com.tanhua.domain.mongo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;

import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.io.Serializable;
import java.util.Date;


/**
 * @author ldy
 * @Package com.tanhua.domain.mongo
 * @date 2021/11/7 0007 下午 11:30
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Document("user_frozen")
public class UserFrozen implements Serializable {
    //唯一id
    @Id
    private ObjectId id;
    //被冻结的用户的id
    private Long userId;
    //冻结时间 1为冻结3天，2为冻结7天，3为永久冻结
    private Integer freezingTime;
    //冻结范围，1为冻结登录，2为冻结发言，3为冻结发布动态
    private Integer freezingRange;
    //冻结原因
    private String reasonsForFreezing;
    //冻结备注
    private String frozenRemarks;
    //解封时间
    private Long outTime;
    //解封时间
    @Indexed(expireAfterSeconds = 0)
    private Date outDate;
    public void setOutTime() {
        switch (this.freezingTime) {
            case 1:
                this.outTime = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 3;
                break;
            case 2:
                this.outTime = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 7;
                break;
            case 3:
                this.outTime = -1L;
        }
    }

    public void setOutDate() {
        if (outTime != -1) {
            outDate = new Date(this.outTime);
        } else {
            outDate = new Date(System.currentTimeMillis() + 3122064000000L);
        }
    }
}
